<template>
  <el-dialog v-model="visible" title="编辑司机信息" :before-close="handleClose">
    <el-form :model="form" label-width="120px">
      <el-form-item label="用户名">
        <el-input v-model="form.username" disabled/>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" show-password/>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="form.name"/>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.phone"/>
      </el-form-item>
      <el-form-item label="所属仓库">
        <el-input v-model="form.wid"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="sureEditAccount">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import {reactive} from "vue";
import {updateDriver} from "@/scripts/data/driver";

export default {
  name: "DriverEdit",
  props: ['driverData', 'callback'],
  data() {
    return {
      visible: false,
      change: false,
      form: reactive({
        username: this.driverData.username,
        password: this.driverData.password,
        name: this.driverData.name,
        phone: this.driverData.phone,
        wid: this.driverData.wid,
        did: this.driverData.did,
      })
    }
  },
  methods: {
    sureEditAccount() {
      this.change = true;
      updateDriver(this.form, this.callback)
      this.visible = false;
    },
    handleClose() {
      this.visible = false;
      if (!this.change) {
        this.callback(-1);
      }
    },
  },
  mounted() {
    this.visible = true;
  }
}
</script>

<style scoped>

</style>